home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte13 / senddoc.c < prev    next >
C/C++ Source or Header  |  1996-04-10  |  5KB  |  180 lines

  1.  
  2. #include <windows.h>  
  3. #include <commctrl.h>
  4. #include "cmc.h"
  5. #include "SendDoc.h"  
  6.  
  7.  
  8. #if defined (WIN32)
  9.     #define IS_WIN32 TRUE
  10. #else
  11.     #define IS_WIN32 FALSE
  12. #endif
  13.  
  14. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  15. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  16. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  17.  
  18. HINSTANCE hInst;   // current instance
  19.  
  20. LPCTSTR lpszAppName = "MyApp";
  21. LPCTSTR lpszTitle   = "Send Document"; 
  22.  
  23.  
  24. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  25.  
  26.  
  27. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  28.                       LPTSTR lpCmdLine, int nCmdShow)
  29. {
  30.    MSG      msg;
  31.    HWND     hWnd; 
  32.    WNDCLASS wc;
  33.  
  34.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  35.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  36.    wc.cbClsExtra    = 0;                      
  37.    wc.cbWndExtra    = 0;                      
  38.    wc.hInstance     = hInstance;              
  39.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  40.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  41.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  42.    wc.lpszMenuName  = lpszAppName;              
  43.    wc.lpszClassName = lpszAppName;              
  44.  
  45.    if ( IS_WIN95 )
  46.    {
  47.       if ( !RegisterWin95( &wc ) )
  48.          return( FALSE );
  49.    }
  50.    else if ( !RegisterClass( &wc ) )
  51.       return( FALSE );
  52.  
  53.    hInst = hInstance; 
  54.  
  55.    hWnd = CreateWindow( lpszAppName, 
  56.                         lpszTitle,    
  57.                         WS_OVERLAPPEDWINDOW, 
  58.                         CW_USEDEFAULT, 0, 
  59.                         CW_USEDEFAULT, 0,  
  60.                         NULL,              
  61.                         NULL,              
  62.                         hInstance,         
  63.                         NULL               
  64.                       );
  65.  
  66.    if ( !hWnd ) 
  67.       return( FALSE );
  68.  
  69.    ShowWindow( hWnd, nCmdShow ); 
  70.    UpdateWindow( hWnd );         
  71.  
  72.    while( GetMessage( &msg, NULL, 0, 0) )   
  73.    {
  74.       TranslateMessage( &msg ); 
  75.       DispatchMessage( &msg );  
  76.    }
  77.  
  78.    return( msg.wParam ); 
  79. }
  80.  
  81.  
  82. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  83. {
  84.    WNDCLASSEX wcex;
  85.  
  86.    wcex.style         = lpwc->style;
  87.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  88.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  89.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  90.    wcex.hInstance     = lpwc->hInstance;
  91.    wcex.hIcon         = lpwc->hIcon;
  92.    wcex.hCursor       = lpwc->hCursor;
  93.    wcex.hbrBackground = lpwc->hbrBackground;
  94.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  95.    wcex.lpszClassName = lpwc->lpszClassName;
  96.  
  97.    // Added elements for Windows 95.
  98.    //...............................
  99.    wcex.cbSize = sizeof(WNDCLASSEX);
  100.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  101.                             IMAGE_ICON, 16, 16,
  102.                             LR_DEFAULTCOLOR );
  103.             
  104.    return RegisterClassEx( &wcex );
  105. }
  106.  
  107.  
  108. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  109. {
  110. static BOOL bInitialize = FALSE;
  111.  
  112.    switch( uMsg )
  113.    {
  114.       case WM_CREATE :
  115.               bInitialize = CMCInitialize();
  116.               break;
  117.  
  118.       case WM_INITMENU :
  119.               EnableMenuItem( (HMENU)wParam, IDM_SEND, 
  120.                               MF_BYCOMMAND | (bInitialize ? MF_ENABLED : MF_GRAYED ) );
  121.               break;
  122.  
  123.       case WM_COMMAND :
  124.               switch( LOWORD( wParam ) )
  125.               {
  126.                  case IDM_SEND :
  127.                         // Send a file..
  128.                         //..............
  129.                         CMCSendDocuments( NULL, "Test Document",
  130.                                           "This is a test message with a document",
  131.                                           CMC_LOGON_UI_ALLOWED | CMC_SEND_UI_REQUESTED,
  132.                                           "file.txt", "Text File.txt", ";", 0 );
  133.                         break;
  134.  
  135.                  case IDM_ABOUT :
  136.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  137.                         break;
  138.  
  139.                  case IDM_EXIT :
  140.                         DestroyWindow( hWnd );
  141.                         break;
  142.               }
  143.               break;
  144.       
  145.       case WM_DESTROY :
  146.               CMCUninitialize();
  147.               PostQuitMessage(0);
  148.               break;
  149.  
  150.       default :
  151.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  152.    }
  153.  
  154.    return( 0L );
  155. }
  156.  
  157.  
  158. LRESULT CALLBACK About( HWND hDlg,           
  159.                         UINT message,        
  160.                         WPARAM wParam,       
  161.                         LPARAM lParam)
  162. {
  163.    switch (message) 
  164.    {
  165.        case WM_INITDIALOG: 
  166.                return (TRUE);
  167.  
  168.        case WM_COMMAND:                              
  169.                if (   LOWORD(wParam) == IDOK         
  170.                    || LOWORD(wParam) == IDCANCEL)    
  171.                {
  172.                        EndDialog(hDlg, TRUE);        
  173.                        return (TRUE);
  174.                }
  175.                break;
  176.    }
  177.  
  178.    return (FALSE); 
  179. }
  180.